/*
 * @Author: lokei
 * @Date: 2022-08-31 15:12:20
 * @LastEditors: lokei
 * @LastEditTime: 2022-09-01 08:50:37
 * @Description: 
 */
package cn.lokei.sim;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.client.RestTemplate;

import com.alibaba.fastjson.JSONObject;

import cn.lokei.sim.entity.Device;

import org.springframework.http.HttpStatus;

@SpringBootApplication
@EnableScheduling
public class SimApplication {

	public static List<Device> device_list = new ArrayList<Device>();

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		SpringApplication.run(SimApplication.class, args);

		RestTemplate restTemplate = new RestTemplate();
		ResponseEntity<JSONObject> responseEntity = restTemplate.getForEntity(
				"https://open.lokei.cn/api/iot/device/ofSim",
				JSONObject.class);
		HttpStatus statusCode = responseEntity.getStatusCode(); // 获取响应码
		if (statusCode == HttpStatus.OK) {
			JSONObject body = responseEntity.getBody();
			JSONObject data = body.getJSONObject("data");
			List<LinkedHashMap<String, Object>> items = (List<LinkedHashMap<String, Object>>) data.get("items");
			for (LinkedHashMap<String, Object> object : items) {
				Device device = new Device((String) object.get("identity"));
				device_list.add(device);
			}
		}
	}

}
